package com.tevintao.marketingsystem.provider;

import android.content.ContentProvider;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.text.TextUtils;

import com.tevintao.marketingsystem.log.LogManager;
import com.tevintao.marketingsystem.services.AccountManager;
import com.tevintao.marketingsystem.tool.SystemPathTool;

public class ReportFriendIconProvider extends ContentProvider {

    private String mAccount = "";

    public ReportFriendIconProvider() {
        if (TextUtils.isEmpty(mAccount)) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String newDataPath = AccountManager.MM_DATA_ROOT + "/" + AccountManager.ACCOUNT_NAME_FILE_NAME;
                    mAccount = SystemPathTool.getOutPutContent(newDataPath);
                    LogManager.getInstance().logError("hookResolver query all mAccount = " + mAccount);
                }
            }).start();
        }
    }

    @Override
    public int delete(Uri uri, String selection, String[] selectionArgs) {
        // Implement this to handle requests to delete one or more rows.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public String getType(Uri uri) {
        // TODO: Implement this to handle requests for the MIME type of the data
        // at the given URI.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public Uri insert(Uri uri, ContentValues values) {
        // TODO: Implement this to handle requests to insert a new row.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public boolean onCreate() {
        // TODO: Implement this to initialize your content provider on startup.
        return false;
    }

    @Override
    public Cursor query(Uri uri, String[] projection, String selection,
                        String[] selectionArgs, String sortOrder) {
        if (TextUtils.isEmpty(mAccount)) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String newDataPath = AccountManager.MM_DATA_ROOT + "/" + AccountManager.ACCOUNT_NAME_FILE_NAME;
                    mAccount = SystemPathTool.getOutPutContent(newDataPath);
                    LogManager.getInstance().logError("hookResolver query all mAccount = " + mAccount);
                }
            }).start();
        }
        return ChatNewChatDB.getInstance().getNoPathFriend(mAccount);
    }

    @Override
    public int update(Uri uri, ContentValues values, String selection,
                      String[] selectionArgs) {
        if (TextUtils.isEmpty(mAccount)) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    String newDataPath = AccountManager.MM_DATA_ROOT + "/" + AccountManager.ACCOUNT_NAME_FILE_NAME;
                    mAccount = SystemPathTool.getOutPutContent(newDataPath);
                    LogManager.getInstance().logError("hookResolver query all mAccount = " + mAccount);
                }
            }).start();
        }
        return ChatNewChatDB.getInstance().updateChatFriendCover(values, selection, selectionArgs);
    }
}
